Skip to content

fix: preserve forward upstream URLs in cURL exports#395

Merged
liaohch3 merged 6 commits into
mainfrom
codex/fix-curl-upstream-url
Jul 22, 2026
Merged

fix: preserve forward upstream URLs in cURL exports#395
liaohch3 merged 6 commits into
mainfrom
codex/fix-curl-upstream-url

Conversation

@YoungCan-Wang

@YoungCan-Wang YoungCan-Wang commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • persist the credential-free upstream origin on every forward-proxy HTTP trace outcome
  • build copied cURL commands from that recorded origin instead of assuming Anthropic
  • recover the host from historical forward traces that predate upstream metadata
  • keep authentication headers redacted in traces and copied commands by design

Problem

Forward-proxy records did not include upstream_base_url, so the viewer fell back to https://api.anthropic.com even when OpenCode or another client used a custom provider. This made copied cURL commands target the wrong service. API credentials remain omitted or redacted intentionally; restoring live keys would turn exported traces into credential leaks.

Fixes #392.

Validation

  • uv lock --check
  • uv run ruff check .
  • uv run ruff format --check .
  • uv run pytest tests/ -x --timeout=60 (990 passed, 25 skipped)
  • focused forward-proxy origin tests, including default ports, credentials, local reverse bridging, and upstream errors
  • real Chromium contract test for current metadata and historical Host fallback
  • uv run python scripts/check_screenshots.py .agents/evidence/pr/issue-392-curl-upstream/opencode-forward-trace-upstream-metadata.png
  • uv run python scripts/verify_screenshots.py against the exported viewer HTML

Evidence

Real trace viewer generated from claude-tap --tap-client opencode with OpenCode 1.16.0. The isolated run captured three records and returned ISSUE392_OK; the model trace records https://opencode.ai plus /zen/v1/chat/completions, and the viewer copied the same full URL.

Real OpenCode trace showing upstream metadata

@YoungCan-Wang
YoungCan-Wang force-pushed the codex/fix-curl-upstream-url branch from 438bed5 to e1e486f Compare July 18, 2026 06:19

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5ffc4a1ff0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread claude_tap/forward_proxy.py Outdated
Comment thread claude_tap/viewer_assets/sections_json.js Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 91244a829a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread claude_tap/forward_proxy.py Outdated
@YoungCan-Wang
YoungCan-Wang requested a review from liaohch3 July 18, 2026 08:11
Resolve the forward proxy trace-filter conflict while preserving upstream URL metadata.

Co-authored-by: Talon <talon@users.noreply.github.com>

@liaohch3 liaohch3 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed after merging current main. The only manual conflict resolution preserves the Codex App trace filter and PR #395 upstream URL metadata together. Local lock, lint, format, focused proxy/viewer tests, and the full test suite pass.

@liaohch3
liaohch3 merged commit ce385bc into main Jul 22, 2026
11 checks passed
@liaohch3
liaohch3 deleted the codex/fix-curl-upstream-url branch July 22, 2026 14:56

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a7fa0310ad

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +139 to +141
const isLoopbackHost = /^(?:localhost|127(?:\.\d{1,3}){3}|\[?::1\]?)(?::\d+)?$/i.test(historicalHost);
const base = e.upstream_base_url
|| (historicalHost && !isLoopbackHost ? `https://${historicalHost}` : 'https://api.anthropic.com');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject unspecified proxy hosts in cURL fallback

For historical records without upstream_base_url, this guard still treats Host: 0.0.0.0:<port> as an upstream provider and copies https://0.0.0.0:<port>/...; fresh evidence is that claude_tap/cli.py:889-892 defaults --tap-no-launch proxy-only mode to bind on 0.0.0.0, so older reverse-proxy traces from that supported mode can store the local listener host rather than the real target. Those cURL exports should keep falling back to the provider/default instead of a dead local proxy address.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: 点击 cURL 后复制出来的 baseURL是虚假的

2 participants